package per.ethan.cloud.consumer.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.messaging.Message;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Ethan
 * @date 2020/03/31 18:22
 */
@Slf4j
@RestController
@EnableBinding(Sink.class)
@RequestMapping("/stream/receive")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class MessageReceiveController {

    @Value("${server.port}")
    private String serverPort;

    @StreamListener(Sink.INPUT)
    public void receive(Message<String> message) {
        log.info("消费者{}接收：{}", serverPort, message.getPayload());
    }

}
